package com.book.controller.admin;

import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.book.entity.Teacher;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;


//用户权限控制类，包括登录权限等
//@author 



@Controller
@RequestMapping("/admin")
public class AuthController {
	
	@Autowired
	private StringRedisTemplate redis; 
   
	@PostMapping("/login")
	public String login(String username, String password ) throws JsonProcessingException  {
		System.out.println("进入   AuthController 的用户");
		  if("admin".equals(username) && "a".equals(password) ) {
			  
			  String userJson = new ObjectMapper().writeValueAsString(new Teacher(username ,password));
			  
			  redis.opsForValue().set("login",userJson);
			  
			  
			  //登录成功
			  return "admin/index"; 
			
	      }else {
	    	  //登录失败
	      }
		  return "admin/login";
}
}